package com.xja.warehouse.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xja.common.utils.PageUtils;
import com.xja.common.utils.Query;

import com.xja.warehouse.dao.ProviderDao;
import com.xja.warehouse.entity.ProviderEntity;
import com.xja.warehouse.service.ProviderService;


@Service("providerService")
public class ProviderServiceImpl extends ServiceImpl<ProviderDao, ProviderEntity> implements ProviderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ProviderEntity> queryWrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        Integer id = (Integer) params.get("id");
        if (StringUtils.isNotBlank(key) || id != null) {
            queryWrapper.eq("id", id)
                    .or().like("providername", key)
                    .or().like("connectionperson", key)
                    .or().like("phone", key);
        }
        IPage<ProviderEntity> page = this.page(
            new Query<ProviderEntity>().getPage(params),
            queryWrapper
        );

        return new PageUtils(page);
    }

}